package cn.vehicle.controller;

import cn.vehicle.biz.core.PlateDetectedBiz;
import cn.vehicle.convert.ZsHttpConvert;
import cn.vehicle.domains.info.GIoInInternalInfo;
import cn.vehicle.domains.info.HeartBeatInternalInfo;
import cn.vehicle.domains.info.PlateDetectedInternalInfo;
import cn.vehicle.domains.info.SnapshotInternalInfo;
import cn.vehicle.domains.vo.Result;
import cn.vehicle.domains.vo.req.zs.ZsGIoInReq;
import cn.vehicle.domains.vo.req.zs.ZsHeartBeatReq;
import cn.vehicle.domains.vo.req.zs.ZsPlateDetectedReq;
import cn.vehicle.domains.vo.req.zs.ZsSnapshotInReq;
import cn.vehicle.domains.vo.res.zs.AlarmInfoPlateRes;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/zs-camera") // 与其他接口路径规范一致，前缀为/api/transport-vehicle
@Slf4j
@Tag(name = "ZsCameraController", description = "相机识别逻辑接口")
public class ZsCameraController {

    @Resource
    private PlateDetectedBiz plateDetectedBiz;

    @Resource
    private ZsHttpConvert zsHttpConvert;

    @PostMapping("/plateDetected")
    public AlarmInfoPlateRes plateDetected(@RequestBody ZsPlateDetectedReq req) {

        PlateDetectedInternalInfo plateDetectedInternalInfo = zsHttpConvert.parseZsPlateDetectedReq(req);
        Boolean result = plateDetectedBiz.receivePlateDetected(plateDetectedInternalInfo);
        return zsHttpConvert.parseAlarmInfoPlate(result, false);

    }



    @PostMapping("/heartBeat")
    public AlarmInfoPlateRes heartBeat(ZsHeartBeatReq req) {
        HeartBeatInternalInfo heartBeatInternalInfo = zsHttpConvert.parseZsHeartBeatReq(req);
        plateDetectedBiz.receiveHeartBeat(heartBeatInternalInfo);
        return zsHttpConvert.parseAlarmInfoPlate(false, true);
    }


    @PostMapping("snapshot")
    public void snapshot(@RequestBody ZsSnapshotInReq req) {
        SnapshotInternalInfo snapshotInternalInfo = zsHttpConvert.parseZsSnapshotInReq(req);
        plateDetectedBiz.receiveSnapshot(snapshotInternalInfo);
    }


    @PostMapping("gIoIn")
    public Result<Void> gIoIn(@RequestBody ZsGIoInReq req) {

        log.info("gIoIn req: {}", JSONObject.toJSONString(req));
        GIoInInternalInfo gIoInInternalInfo = zsHttpConvert.parseZsGIoInReq(req);
        plateDetectedBiz.receiveGIoIn(gIoInInternalInfo);
        return Result.success();

    }





}
